<?php/*Plugin Name: Estatik Calculator WidgetPlugin URI: http://estatik.netDescription: A simple mortgage calculator widgetVersion: 1.2.2Author: EstatikAuthor URI: http://estatik.net*//*-----------------------------------------------------------------------------------*//* Include CSS *//*-----------------------------------------------------------------------------------*/ function estatik_calc_css() {			wp_enqueue_style( 'opensans', 		'//fonts.googleapis.com/css?family=Open+Sans%3A300%2C400%22+rel%3D%22stylesheet', false, '1.0' );	wp_enqueue_style( 'estatik-calc-css-rangeslider-normalize', 		plugins_url( 'front/js/rangeslider/css/normalize.css', __FILE__ ), 		false );	wp_enqueue_style( 'estatik-calc-css-rangeslider', 		plugins_url( 'front/js/rangeslider/css/ion.rangeSlider.css', __FILE__ ), 		false );	wp_enqueue_style( 'estatik-calc-css-rangeslider-skin', 		plugins_url( 'front/js/rangeslider/css/ion.rangeSlider.skinFlat.css', __FILE__ ), 		false );	wp_enqueue_style( 'estatik-calc-css-chartist', 		plugins_url( 'front/js/chartist.min.css', __FILE__, false, '1.0' ), 		false );	wp_enqueue_style( 'estatik-calc-css', plugins_url( 'front/css/es_calc_style.css', __FILE__ ), false, '1.0' );	include_once("front/css/es_calc_color.php");}add_action( 'wp_print_styles', 'estatik_calc_css' );/*-----------------------------------------------------------------------------------*//* Include JS *//*-----------------------------------------------------------------------------------*/function estatik_calc_scripts() {	wp_enqueue_script( 'estatik-calc-js-rangeslider', 		plugins_url( 'front/js/rangeslider/js/ion-rangeSlider/ion.rangeSlider.min.js', __FILE__ ), 		array('jquery'), 		'1.0', true );	wp_enqueue_script( 'estatik-calc-js-chartist', 		plugins_url( 'front/js/chartist.min.js', __FILE__ ), array(), '1.0', true );	wp_enqueue_script( 'estatik-calc-js-chart', 		plugins_url( 'front/js/loader.js', __FILE__ ),		array(), '1.0', true );			wp_enqueue_script( 'estatik-calc-js', plugins_url( 'front/js/calc.js', __FILE__ ), 		array('jquery', 'estatik-calc-js-rangeslider'), 		'1.0', true );}add_action( 'wp_enqueue_scripts', 'estatik_calc_scripts' );/*-----------------------------------------------------------------------------------*//* Add Settings page *//*-----------------------------------------------------------------------------------*/class estatik_calculator_options_page {	private $page_title;	private $page_subtitle;	private $author_email;	private $settings;	function __construct() {                $this->settings = (object)get_option('estatik_calculator_settings');                		add_action( 'admin_enqueue_scripts', array(				$this,				'admin_scripts'			) );		add_action( 'admin_menu', array( $this, 'admin_menu' ) );	}	function admin_scripts() {		wp_enqueue_style( 'opensans', '//fonts.googleapis.com/css?family=Open+Sans%3A300%2C400%22+rel%3D%22stylesheet', false, '1.0' );			wp_enqueue_style( 'wp-color-picker' );	    wp_enqueue_style( 'es_calc_admin_css', plugins_url( 'admin/admin_style.css', __FILE__ ), false, '1.0' );	    wp_enqueue_script( 'es_calc_admin_js', plugins_url( 'admin/admin_scripts.js', __FILE__ ), 	    	array('jquery', 'wp-color-picker'), '1.0', true );	}	function admin_menu() {		$this->page_title = __( 'Estatik Mortgage Calculator Options', 'es-calc' );		$this->author_site = 'https://estatik.net/contact-us/';		$this->page_subtitle = sprintf( __( "Please set up Calculator settings according to your needs. If you have any questions, need support or would like to customise the plugin, <a href='%s'>contact us</a>", 'es-calc'), $this->author_site );		add_options_page(			$this->page_title,			__( 'Estatik Mortgage Calculator', 'es-calc' ),			'manage_options',			'options_page_es_calc',			array(				$this,				'settings_page'			)		);	}	function  settings_page() {		include_once('admin/options_page.php');		// echo $this->page_title, 'This is the page content';	}}new estatik_calculator_options_page;/*-----------------------------------------------------------------------------------*//* Register Widget *//*-----------------------------------------------------------------------------------*/if ( ! function_exists( 'es_show_on_pages_selector' ) ) :  function es_show_on_pages_selector($field_name, $show_on_pages) {    ?>    <p class="wrap">      <label>        <?php _e('Show On Pages', 'es-plugin'); ?>      </label>      <select name="<?php echo $field_name; ?>" class="show_on_pages">        <?php        $options = array(          'all_pages' => __('All pages', 'es-theme'),          'show_on_checked_pages' => __('Show on checked pages', 'es-theme'),          'hide_on_checked_pages' => __('Hide on checked pages', 'es-theme')        );        foreach ( $options as $key => $value ) {          $selected = $show_on_pages == $key ? 'selected="selected"' : '';          echo "<option value='$key' id='$key' $selected>$value</option>";        }        ?>      </select>    </p>    <?php  }endif;if ( ! function_exists( 'es_show_pages_selector' ) ) :  function es_show_pages_selector($title, $field_name, $select_pages, $add_types=true, $multiple=true) {    if ( $multiple ) {      $data_array = '[]';      $multiselect = 'multiple';    } else {      $data_array = '';      $multiselect = '';      $select_pages = array($select_pages);    }    ?>    <p class="wrap select_pages">      <label><?php echo $title; ?></label>      <select name="<?php echo $field_name, $data_array; ?>" <?php echo $multiselect ?>>        <?php        $pages = es_get_page_list($add_types);        foreach ( $pages as $key => $title ){          $selected = in_array($key, $select_pages) ? "selected='selected'" : '';          echo "<option value='$key' $selected>$title</option>";        }        ?>      </select>    </p>    <?php  }endif;if ( ! function_exists( 'es_get_page_list' ) ) :  function es_get_page_list($add_types=true) {    $all_pages = get_pages(      array(        'sort_order' => 'ASC',        'sort_column' => 'post_title',        'post_type' => 'page',        'post_status' => 'publish'      ));    $pages = array();    foreach ( $all_pages as $page ) {      $pages[$page->ID] = $page->post_title;    }    if ( $add_types ) {      $pages['archive_page']  = __('Archive Page', 'es-plugin');      $pages['single_page']   = __('Single Page', 'es-plugin');      $pages['category_page'] = __('Category Page', 'es-plugin');      $pages['search_page']   = __('Search Page', 'es-plugin');    }    return $pages;  }endif;if ( ! function_exists( 'es_show_widget' ) ) :  function es_show_widget($instance) {    $queried_object = get_queried_object();    if ( !$queried_object ) return false;    $show_on_pages = $instance['show_on_pages'];    if ( $show_on_pages == 'all_pages' ) return true;    $select_pages = $instance['select_pages'];    $post_info = array( $queried_object->ID );    if ( is_archive() )   $post_info[] = 'archive_page';    if ( is_single() )    $post_info[] = 'single_page';    if ( is_category() )  $post_info[] = 'category_page';    if ( is_search() )    $post_info[] = 'search_page';    if ( $show_on_pages == 'show_on_checked_pages'      && array_intersect($post_info, $select_pages) == true ) return true;    if ( $show_on_pages == 'hide_on_checked_pages'      && array_intersect($post_info, $select_pages) == false ) return true;    return false;  }endif;class EstatikCalculator extends WP_Widget {	function __construct() {	   $widget_ops = array('description' => 'Display Estatik calculator.' );	   parent::__construct(false, 'Estatik Calculator', $widget_ops);      	}	function widget($args, $instance) {  	    if ( es_show_widget($instance) === false ) return;                $settings = (object)get_option('estatik_calculator_settings');		// extract( $args );		$title = $instance['title'];		$layout = $instance['layout'];                $number_format = explode('|', $settings->number_format);                $decimals = $number_format[0];                $decimalpoint = $number_format[1];                $separator = $number_format[2];		// $currency = $instance['currency'];		// $format = $instance['format'];		// $period = $instance['period'];		// $popup = $instance['popup'];				echo $before_widget;		include('front/es_calc_form.php');			echo $after_widget;   	}   	function update($new_instance, $old_instance) {                	   	return $new_instance;   	}   	function form($instance) {   		$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';		$layout = isset( $instance['layout'] ) ? esc_attr( $instance['layout'] ) : 'vertical';		$currency = isset( $instance['currency'] ) ? esc_attr( $instance['currency'] ) : '';		$format = isset( $instance['format'] ) ? esc_attr( $instance['format'] ) : '';		$period = isset( $instance['period'] ) ? esc_attr( $instance['period'] ) : '';		$popup = isset( $instance['popup'] ) ? esc_attr( $instance['popup'] ) : '';	    $show_on_pages = empty( $instance['show_on_pages'] ) ? 'all_pages' : esc_attr($instance['show_on_pages']);	    $select_pages = empty( $instance['select_pages'] ) ? array() : $instance['select_pages'];		?>		<p>		   <label for="<?php echo $this->get_field_id('title'); ?>">Title</label>		   <input type="text" name="<?php echo $this->get_field_name('title'); ?>"  value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />		   <a href="<?php echo admin_url( 'options-general.php?page=options_page_slug' )?>">Settings</a>		   <!-- <label for="<?php echo $this->get_field_id('currency'); ?>">Currency</label>		   <input type="text" name="<?php echo $this->get_field_name('currency'); ?>"  value="<?php echo $currency; ?>" class="widefat" id="<?php echo $this->get_field_id('currency'); ?>" />		   <label for="<?php echo $this->get_field_id('format'); ?>">Number format</label>		   <input type="text" name="<?php echo $this->get_field_name('format'); ?>"  value="<?php echo $format; ?>" class="widefat" id="<?php echo $this->get_field_id('format'); ?>" />		   <label for="<?php echo $this->get_field_id('period'); ?>">Amortization period</label>		   <input type="text" name="<?php echo $this->get_field_name('period'); ?>"  value="<?php echo $period; ?>" class="widefat" id="<?php echo $this->get_field_id('period'); ?>" />		   <label for="<?php echo $this->get_field_id('popup'); ?>">Select popup</label>		   <input type="text" name="<?php echo $this->get_field_name('popup'); ?>"  value="<?php echo $popup; ?>" class="widefat" id="<?php echo $this->get_field_id('popup'); ?>" /> -->		</p>	    <p>	        <label for="<?php echo $this->get_field_id( 'layout' ); ?>"><?php _e( 'Layout:' ) ?></label>	        <br/>	        <input type="radio" name="<?php echo $this->get_field_name( 'layout' ); ?>" 	        	<?php if ( $layout == 'vertical') echo 'checked' ?>	        	value="vertical"/><?php _e('Vertical', 'es-plugin') ?><br/>	        <input type="radio" name="<?php echo $this->get_field_name( 'layout' ); ?>" 	        	<?php if ( $layout == 'horizontal') echo 'checked' ?>	        	value="horizontal"/><?php _e('Horizontal', 'es-plugin') ?>	    </p>		<?php	    	es_show_on_pages_selector($this->get_field_name('show_on_pages'), $show_on_pages);	    	es_show_pages_selector(__('Select Pages', 'es-plugin'), $this->get_field_name('select_pages'), $select_pages);	}} add_action( 'widgets_init', create_function( '', 'register_widget("EstatikCalculator");' ) );function estatik_calculator_activate() {    add_option( 'estatik_calculator_settings',             array(                'currency' 		 => '$',                'number_format' 	 => '2|,|.',                'amortization_period' 	 => 'annually',                'select_popup'           => 'graph',                'default_purchase_price' => '300000',                'max_purchase_price' 	 => '1000000',                'down_payment' 		 => 'off',                'default_down_payment'   => '30000',                'default_term'           => '5',                'max_term'           	 => '20',                // 'interest_rate'          => sanitize_text_field($_POST['interest_rate']),                'default_interest_rate'  => '2.5',                'property_tax'           => 'off',                'default_property_tax'   => '3000',                'max_property_tax'   	 => '10000',                'home_insurance'         => 'off',                'default_home_insurance' => '1000',                'max_home_insurance' 	 => '3000',                'pmi'                    => 'off',                'default_pmi' 	 	 => '1000',                'max_pmi' 	 	 => '300000',                'color'			 => '#60d401'                )            );      }register_activation_hook( __FILE__, 'estatik_calculator_activate' );function plugin_add_settings_link( $links ) {    $settings_link = '<a href="options-general.php?page=options_page_es_calc">' . __( 'Settings' ) . '</a>';    array_push( $links, $settings_link );  	return $links;}$plugin = plugin_basename( __FILE__ );add_filter( "plugin_action_links_$plugin", 'plugin_add_settings_link' );function es_mortgage_calculator( $atts ) {	$settings = (object)get_option('estatik_calculator_settings');	$layout = empty($atts['layout']) ? 'horizontal' : $atts['layout'];        $number_format = explode('|', $settings->number_format);        $decimals = $number_format[0];        $decimalpoint = $number_format[1];        $separator = $number_format[2];        ob_start();	include('front/es_calc_form.php');    return ob_get_clean();}add_shortcode( 'es_mortgage_calculator', 'es_mortgage_calculator' );if ( !function_exists('es_dump') ) {    function es_dump($var) {        echo '<pre>';        print_r($var);        echo '</pre>';    }}